/**
 * 
 */
package com.demo2do.strawberry.dao;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.demo2do.core.persistence.GenericDaoSupport;
import com.demo2do.strawberry.entity.startup.Startup;

/**
 * @author lute
 *
 */
@Repository("startupDao")
public class StartupDao {
	
	@Autowired
	private GenericDaoSupport genericDaoSupport;
	
	/**
	 * @param ids
	 * @param name
	 * @return
	 */
	public List<Startup> getStartups(Set<String> ids, String name) {
		
		List<Startup> startups = new ArrayList<Startup>();
		
		if(org.apache.commons.lang.StringUtils.isNotEmpty(name)) {
			
			for(String id : ids) {
				Startup startup = genericDaoSupport.load(Startup.class, Long.valueOf(id));
				if(startup.getProfile().getName().indexOf(name) != -1) {
					startups.add(startup);
				}
			}
			
		} else {
			
			for(String id : ids) {
				Startup startup = genericDaoSupport.load(Startup.class, Long.valueOf(id));
				startups.add(startup);
			}
		}
		
		return startups;
		
	}

}
